package com.scala.actor

import scala.actors.Actor

object Boot {

  def main(args: Array[String]) {
    val actor = new MyActor
    actor.start()
    actor ! "start"
    actor ! "stop"
    println("消息发送完成！")
    actor ! "exit"
  }
}

class MyActor extends Actor {

  override def act(): Unit = {
    while (true) {
      receive {
        case "start" => {
          println("starting ...")
          Thread.sleep(3000)
          println(Thread.currentThread().getName)
          println("started")
        }
        case "stop" => {
          println("stopping ...")
          Thread.sleep(3000)
          println(Thread.currentThread().getName)
          println("stopped ...")
        }
        case "exit" => {
          exit()
        }
      }
    }
  }
}